package Test测试;
//力扣290 单词旋律
public class Test3 {
    public static void main(String[] args) {


        String str1 = "abba" ;

        String str2 = "dog dog dog dog" ;


        boolean a = wordPatter(str1,str2);
        System.out.println(a);


    }

    public static boolean wordPatter(String pattern, String s){

        if(pattern == null || s == null){
            return false;
        }

        String[] result1 = pattern.split("") ; // 按照空格拆分

        String[] result2 = s.split(" ") ; // 按照空格拆分


        if(result2.length != result1.length){
            return false;
        }
        if (result2.length == 1)
            return true;

        for (int i = 0; i < result2.length; i++) {

            for (int j = 0; j < result2.length; j++) {

                if( result1[i].equals( result1[j]) ){
                    if(! result2[i].equals(result2[j]) ){
                        return false;
                    }
                }else{

                    if( result2[i].equals(result2[j]) ){
                        return false;
                    }

                }


            }
        }

        return true;
    }


}
